package ro.isdc.training.jpa.student.domain;

import ro.isdc.training.jpa.course.domain.Course;
import ro.isdc.training.jpa.misc.domain.AssociativeEntity;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * An enrollment is an association between course and student.
 * 
 * @author Andrei Chirila
 */
public class Enrollment extends AssociativeEntity {

  /**
   * Generated Serial Version UID
   */
  private static final long serialVersionUID = -2201693193557301760L;

  /**
   * Enrollment composite id.
   */
  private EnrollmentId enrollmentId;

  /**
   * Course
   */
  private Course course;

  /**
   * Student
   */
  private Student student;

  /**
   * @return the enrollmentId
   */
  public EnrollmentId getEnrollmentId() {
    return enrollmentId;
  }

  /**
   * @param enrollementId
   *          the enrollementId to set
   */
  public void setEnrollmentId(final EnrollmentId enrollmentId) {
    this.enrollmentId = enrollmentId;
  }

  /**
   * @return the course
   */
  public Course getCourse() {
    return course;
  }

  /**
   * @param course
   *          the course to set
   */
  public void setCourse(final Course course) {
    this.course = course;
  }

  /**
   * @return the student
   */
  public Student getStudent() {
    return student;
  }

  /**
   * @param student
   *          the student to set
   */
  public void setStudent(final Student student) {
    this.student = student;
  }

  /**
   * @see java.lang.Object#equals(Object)
   */
  public boolean equals(final Object object) {
    if (object == this) {
      return true;
    }
    if (!(object instanceof Enrollment)) {
      return false;
    }
    Enrollment rhs = (Enrollment) object;
    return new EqualsBuilder().append(this.enrollmentId, rhs.enrollmentId)
        .isEquals();
  }

  /**
   * @see java.lang.Object#hashCode()
   */
  public int hashCode() {
    return new HashCodeBuilder(-423210317, -948117313)
        .append(this.enrollmentId).toHashCode();
  }

}
